<template>
  <div id="box">
    <div class="head-box">
      <span class="iconfont icon-guanbi"></span>
      <span>帮助</span>
    </div>
    <div class="m-box">
      <p class="welcom">欢迎来到猫眼</p>
      <div class="tel-number">
        &nbsp;&nbsp;&nbsp;<span>+86</span><input type="text" v-model="userPhone" placeholder="请输入手机号" @blur="blurFn" />
        <!-- <span v-text="msg">错误</span> -->
      </div>
      <div class="tel-number">
        <input type="text" v-model="email" placeholder="请输入邮箱" />
        <!-- <span>错误</span> -->
      </div>
      <div class="tel-number">
        <input type="text" v-model="userPassword" placeholder="请输入6位数字密码" @blur="passwordBlur" />
        <!-- <span>错误</span> -->
      </div>
      <div class="tel-number">
        <input type="text" v-model="code" placeholder="请输入验证码" />
        <!-- <span>错误</span> -->
      </div>

      <!--<div class="agree">-->
        <!--<input type="checkbox"  checked ='checked'/><span>我已阅读并同意<i>《猫眼用户服务协议》、《隐私政策》</i>-->
          <!--并授权猫眼使用该猫眼账号信息(如昵:称、头像、收货地址) 以便统一管理 '-->
        <!--</span>-->
      <!--</div>-->

      <p class="yanzheng" @click="regmimaFn">获取验证码</p>
      <p class="reg" @click="zhuce">注册</p>

      <p class="mima">
        <router-link to="/login"><span>已注册用户直接登录</span></router-link>
      </p>
    </div>
    <div class="way">
      <span class="iconfont icon-weixin"></span>
      <span class="iconfont icon-QQ"></span>
    </div>
  </div>
</template>

<script>
  import axios from "axios";
  import Vue from "vue";

  import { Toast } from "vant";
  Vue.use(Toast);

  export default {
    name: "zhuce",
    data() {
      return {
        userPhone: "",
        userPassword: "",
        email: "",
        code: "",
        msg: "",
      };
    },
    methods: {
      // 手机号是否被使用验证
      blurFn() {
        let reg = /^(?:(?:\+|00)86)?1[3-9]\d{9}$/;
        if (reg.test(this.userPhone)) {
          axios({
            url: "/qf-shop/user/validateuserPhone",
            params: {
              //地址栏数据
              userPhone: this.userPhone,
            },
          }).then((res) => {
            if (res.data.code == 1) {
              return;
            } else if (res.data.code == 0) {
              this.msg = "手机号已被注册";
            }
          });
        } else {
          Toast.fail("亲，请输入正确的手机号");
        }
      },
      //邮箱验证码
      regmimaFn() {
        let reg =/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
        if (reg.test(this.email)) {
          axios({
            url: "/qf-shop-user/user/getCode",
            method: "POST",
            params: {
              //地址栏数据
              email: this.email,
            },
          }).then((res) => console.log(res));
          Toast.success("亲，正确的邮箱");
        } else {
          Toast.fail("亲，请输入正确的邮箱");
        }
      },
      //密码正则验证
      passwordBlur() {
        let reg = /^\d{6,}$/;
        if (!reg.test(this.userPassword)) {
          Toast("亲，请输入6位密码");
        }
      },
      zhuce() {
        //注册验证
        axios({
          url: "/qf-shop-user/user/registry",
          method: "POST",
          data: {
            //地址栏数据
            userPhone: this.userPhone,
            userPassword: this.userPassword,
            email: this.email,
            code: this.code,
          },
          headers: {
            "Content-Type": "application/json",
          }, //php 默认要求传递请求头
        }).then((res) => {
          Toast.success("注册成功");
          this.$cookies.set("passPhone", this.userPhone);
          this.$cookies.set("username", "一罐啤酒");
          setTimeout(() => {
            this.$router.push("/dlpage");
          }, 1000);
        });
      },
    },
  };
</script>

<style scoped>
  #box {
    height: 100%;
    background-color: #fff;
    font-size: 0.14rem;
  }
  .head-box {
    height: 0.44rem;
    background-color: #fff;
    font-size: 0.14rem;
    padding: 0.16rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  .head-box span {
    font-size: 0.18rem;
    color: red;
  }
  .m-box {
    height: 4.75rem;
    background-color: #fff;
    padding: 0 0.22rem;
  }
  .welcom {
    font-size: 0.26rem;
    height: 1rem;
    line-height: 1rem;
  }
  .tel-number {
    height: 0.48rem;
    line-height: 0.48rem;
    border-bottom: 1px solid #979797;
    background-color: #fff;
    justify-content: space-between;
  }
  .tel-number span {
    font-size: 0.11rem;
    margin-top: 0.05rem;
    margin-bottom: 0.48rem;
  }
  .tel-number input {
    font-size: 0.14rem;
    height: 0.44rem;
    text-decoration: none;
    border: 0;
    line-height: 0.44rem;
    padding-left: 0.1rem;
  }
  .weizhuce {
    color: #979797;
    margin-bottom: 0.48rem;
    margin-top: 0.05rem;
  }
  .agree {
    height: 0.5rem;
    display: flex;
    justify-content: flex-start;
    font-size: 12px;
    color: #979797;
    line-height: 0.18rem;
    margin-top: 0.2rem;
  }
  .agree input {
    margin-top: 0.05rem;
  }
  .agree span {
    display: inline-block;
    width: 2.56rem;
    height: 0.46rem;
    margin-left: 0.05rem;
  }
  .agree span i {
    color: #dd4d41;
  }
  .reg {
    height: 0.46rem;
    /* width: 2.96rem; */
    background-color: #dd4d41;
    color: #fff;
    line-height: 0.46rem;
    text-align: center;
    border-radius: 0.05rem;
    margin-top: 0.1rem;
    margin-bottom: 0.2rem;
  }
  .yanzheng {
    height: 0.3rem;
    line-height: 0.3rem;
    background-color: #dd4d41;
    text-align: center;
    color: #fff;
    border-radius: 0.05rem;
    margin-top: 0.1rem;
  }
  .mima {
    font-size: 0.12rem;
    color: #262626;
    display: flex;
    justify-content: space-between;
  }
  .m-box .mima span:nth-child(1) {
    color: red;
  }
  .way {
    width: 1.1rem;
    height: 0.5rem;
    background-color: #fff;
    margin: auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 0.4rem;
  }
  .way .iconfont {
    font-size: 0.38rem;
  }

  .way span {
    border: 0.01rem solid #979797;
    border-radius: 50%;
  }
  .way span:nth-child(1) {
    background-color: #72bf51;
  }
  .way span:nth-child(2) {
    background-color: #54b5e1;
  }
  .icon-weixin {
    color: #fff;
  }
  .icon-QQ {
    color: #fff;
  }
</style>

